import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import ViewUI from 'view-design';
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import i18n from '@/locale'
import config from '@/config'
import installPlugin from '@/plugin'
import Cookie from 'js-cookie'
import iviewArea from 'iview-area'
import formCreate from '@form-create/iview'
import vuePrototype from './libs/vuePrototype'



// import style
import 'view-design/dist/styles/iview.css';
import './index.less'
import '@/assets/my_font/iconfont.css'
import '@/assets/new_font/iconfont.css'
import TreeTable from 'tree-table-vue'
import VOrgTree from 'v-org-tree'
import 'v-org-tree/dist/v-org-tree.css'
import './style/index.scss'
import VueJsonp from 'vue-jsonp'
import Common from './common'
import 'lib-flexible'
import _ from 'lodash'
// platform
import platform from './config/platform'
// 校验
import publicStatus from './config/publicStatus'
// 获取枚举
import { hasOneOf, getEnumerations, filterTree, filterOrg, getZero, getAll, formatterDate, downLoadExcel } from '@/libs/tools'
// Vue.prototype.$getEnumerations = getEnumerations;
// Vue.prototype.$filterTree = filterTree;
// Vue.prototype.$filterOrg = filterOrg;
// Vue.prototype.$getZero = getZero;
// Vue.prototype.$getAll = getAll;
// Vue.prototype.$formatterDate = formatterDate;
// Vue.prototype.$hasOneOf = hasOneOf;
// Vue.prototype.$downLoadExcel = downLoadExcel;
// tools工具类
import tools from '@/libs/tools'

// moment日期
import moment from 'moment'
// 打印
import Print from 'vue-print-nb'
// ending...
import md5 from './libs/md5'
import '../my-theme/index.less'
// 拖拽
import draggable from "vuedraggable"
Vue.component('draggable', draggable)
    // ending...
    // bus
Vue.prototype.$bus = new Vue()
    // ending...
import VueKonva from 'vue-konva';
Vue.use(VueKonva);
// ending...
import VueCropper from 'vue-cropper'
Vue.prototype.$_ = _
Vue.prototype.$platform = platform
Object.keys(publicStatus).forEach(el => {
    Vue.prototype['$' + el] = publicStatus[el]
})
Object.keys(tools).forEach(it => {
    Vue.prototype[`$${it}`] = tools[it]
})
Vue.prototype.$moment = moment
Vue.use(Print)
Vue.prototype.$md5 = md5

Vue.use(Common)

Vue.use(VueJsonp)
Vue.use(ElementUI)
Vue.use(ViewUI, {
    i18n: function(path, options) {
        let value = i18n.t(path, options)
        if (value !== null && value !== undefined) {
            return value
        }
        return ''
    }
})


Vue.use(TreeTable)
Vue.use(VOrgTree)

Vue.use(iviewArea)

let computedBaseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : process.env.NODE_ENV === 'testing' ? config.baseUrl.test : config.baseUrl.pro
Vue.prototype.$computedBaseUrl = computedBaseUrl
Vue.use(formCreate)
Vue.use(VueCropper)
    /**
     * @description 注册admin内置插件
     */
installPlugin(Vue)
    /**
     * @description 生产环境关掉提示
     */
Vue.config.productionTip = false
    /**
     * @description 全局注册应用配置
     */
Vue.prototype.$config = config
Vue.prototype.$imageUrl = process.env.NODE_ENV == 'development' ? config.imgUrl.dev : config.imgUrl.prod
Object.keys(vuePrototype).map(key => {
    Vue.prototype[key] = vuePrototype[key]
})

let instance = null

function render(props = {}) {
    const { container } = props
    instance = new Vue({
        router,
        store,
        render: h => h(App)
    }).$mount(container ? container.querySelector('#app') : '#app')
}

if (window.__POWERED_BY_QIANKUN__) {
    __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__
}
if (!window.__POWERED_BY_QIANKUN__) {
    render()
}

export async function bootstrap() {}

export async function mount(props) {
    let { userId } = props.user
    store.commit('setUserId', userId)

    if (process.env.NODE_ENV === 'production') {
        Cookie.set('token', '', { path: '/', expires: 7 })
    } else {
        Cookie.set('token', '', { path: '', expires: 7 })
    }
    render(props)
}
export async function unmount() {
    instance.$destroy()
    instance = null
}